﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using Microsoft.Maps.MapControl;
using System.Xml.Serialization;
using System.IO;
using System.Text;

namespace SilverlightMapCreator
{
    public static class GeoHelper
    {
        public static String GenerateXMLForOneRoute(List<List<Location>> locList)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List<List<Location>>));
            MemoryStream stream = new MemoryStream();
            TextWriter writer = new StreamWriter(stream, Encoding.Unicode);


            serializer.Serialize(writer, locList);
            int count = (int)stream.Length; // saves object in memory stream

            byte[] arr = new byte[count];
            stream.Seek(0, SeekOrigin.Begin);
            // copy stream contents in byte array

            stream.Read(arr, 0, count);

            String val = UnicodeEncoding.Unicode.GetString(arr, 0, arr.Length);
            return val;
        }

        public static String GenerateXMLForRoutes(List<List<List<Location>>> locList)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(List<List<List<Location>>>));
            MemoryStream stream = new MemoryStream();
            TextWriter writer = new StreamWriter(stream, Encoding.Unicode);


            serializer.Serialize(writer, locList);
            int count = (int)stream.Length; // saves object in memory stream

            byte[] arr = new byte[count];
            stream.Seek(0, SeekOrigin.Begin);
            // copy stream contents in byte array

            stream.Read(arr, 0, count);

            String val = UnicodeEncoding.Unicode.GetString(arr, 0, arr.Length);
            return val;
        }
    }
}
